package cn.gcyl.module.biz.controller.admin.privacy;

import cn.gcyl.framework.apilog.core.annotation.ApiAccessLog;
import cn.gcyl.framework.common.pojo.CommonResult;
import cn.gcyl.framework.common.pojo.PageParam;
import cn.gcyl.framework.common.pojo.PageResult;
import cn.gcyl.framework.common.util.object.BeanUtils;
import cn.gcyl.framework.excel.core.util.ExcelUtils;
import cn.gcyl.module.biz.controller.admin.privacy.vo.*;
import cn.gcyl.module.biz.dal.dataobject.privacy.PrivacyDO;
import cn.gcyl.module.biz.service.privacy.PrivacyService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

import static cn.gcyl.framework.apilog.core.enums.OperateTypeEnum.*;
import static cn.gcyl.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 隐私政策")
@RestController
@RequestMapping("/biz/privacy")
@Validated
public class PrivacyController {

    @Resource
    private PrivacyService privacyService;

//    @PostMapping("/create")
//    @Operation(summary = "创建隐私政策")
//    @PreAuthorize("@ss.hasPermission('biz:privacy:create')")
//    public CommonResult<Long> createPrivacy(@Valid @RequestBody PrivacySaveReqVO createReqVO) {
//        return success(privacyService.createPrivacy(createReqVO));
//    }

    @PutMapping("/update")
    @Operation(summary = "更新隐私政策")
//    @PreAuthorize("@ss.hasPermission('biz:privacy:update')")
    public CommonResult<Boolean> updatePrivacy(@Valid @RequestBody PrivacySaveReqVO updateReqVO) {
        privacyService.updatePrivacy(updateReqVO);
        return success(true);
    }

//    @DeleteMapping("/delete")
//    @Operation(summary = "删除隐私政策")
//    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('biz:privacy:delete')")
//    public CommonResult<Boolean> deletePrivacy(@RequestParam("id") Long id) {
//        privacyService.deletePrivacy(id);
//        return success(true);
//    }
//
//    @DeleteMapping("/delete-list")
//    @Parameter(name = "ids", description = "编号", required = true)
//    @Operation(summary = "批量删除隐私政策")
//                @PreAuthorize("@ss.hasPermission('biz:privacy:delete')")
//    public CommonResult<Boolean> deletePrivacyList(@RequestParam("ids") List<Long> ids) {
//        privacyService.deletePrivacyListByIds(ids);
//        return success(true);
//    }
//
    @GetMapping("/get")
    @Operation(summary = "获得隐私政策")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
//    @PreAuthorize("@ss.hasPermission('biz:privacy:query')")
    public CommonResult<PrivacyRespVO> getPrivacy(@RequestParam("id") Long id) {
        PrivacyDO privacy = privacyService.getPrivacy(id);
        return success(BeanUtils.toBean(privacy, PrivacyRespVO.class));
    }
//
    @GetMapping("/page")
    @Operation(summary = "获得隐私政策分页")
//    @PreAuthorize("@ss.hasPermission('biz:privacy:query')")
    public CommonResult<PageResult<PrivacyRespVO>> getPrivacyPage(@Valid PrivacyPageReqVO pageReqVO) {
        PageResult<PrivacyDO> pageResult = privacyService.getPrivacyPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, PrivacyRespVO.class));
    }
//
//    @GetMapping("/export-excel")
//    @Operation(summary = "导出隐私政策 Excel")
////    @PreAuthorize("@ss.hasPermission('biz:privacy:export')")
//    @ApiAccessLog(operateType = EXPORT)
//    public void exportPrivacyExcel(@Valid PrivacyPageReqVO pageReqVO,
//              HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<PrivacyDO> list = privacyService.getPrivacyPage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "隐私政策.xls", "数据", PrivacyRespVO.class,
//                        BeanUtils.toBean(list, PrivacyRespVO.class));
//    }

}